﻿using Jayden.Dll.Core.Persistence.Queries.Enums;

namespace Jayden.Dll.Core.Persistence.Queries
{
	public class QueryOrderField
	{
		private QueryOrderFieldDirection m_Direction;
		private string m_TableName;
		private string m_FieldName;
		private string m_AliasName;

		public QueryOrderField() { }
		public QueryOrderField(QueryOrderFieldDirection direction, string tableName, string fieldName, string aliasName = null)
		{
			m_Direction = direction;
			m_TableName = tableName;
			m_FieldName = fieldName;
			m_AliasName = aliasName;
		}

		public QueryOrderFieldDirection Direction { get { return m_Direction; } set { m_Direction = value; } }
		public string TableName { get { return m_TableName; } set { m_TableName = value; } }
		public string FieldName { get { return m_FieldName; } set { m_FieldName = value; } }
		public string AliasName { get { return m_AliasName; } set { m_AliasName = value; } }
		public string FullName { get { return m_TableName == null ? m_FieldName : string.Format("{0}.{1}", m_TableName, m_FieldName); } }
		public string QueryName { get { return m_AliasName != null ? m_AliasName : FullName; } }

		public override string ToString()
		{
			return string.Format("{0} {1}", QueryName, Direction == QueryOrderFieldDirection.Ascending ? "ASC" : "DESC");
		}
	}
}
